#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e5 + 5;
int t, n;
string s;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;

    while (t--) {
        cin >> n;
        cin >> s;

        if (n == 1 || s[0] <= s[1]) {
            cout << s[0] << s[0] << endl;
            continue;
        }

        string s2 = "";
        s2 += s[0];

        for (int i = 1; i < n; i++) {
            if (s[i] <= s[i-1]) {
                s2 += s[i];
            } else break;
        }

        cout << s2;
        reverse(s2.begin(), s2.end());
        cout << s2 << endl;
    }
    return 0;
}